import 'package:flutter/material.dart';

import 'package:flutter_demo/widgets/textWidget.dart';
import 'package:flutter_demo/widgets/groupSlotWidget.dart';
import 'package:flutter_demo/widgets/groupHeaderWidget.dart';

import 'package:flutter_demo/models/groupBookingItem.dart';

// 团购组
class MGroupBooking extends StatelessWidget {
  final List<GroupBookingItem> items;
  final String title;

  MGroupBooking({
    @required this.items,
    this.title = "好物拼团",
  }) : assert(items != null);

  @override
  Widget build(BuildContext context) {
    return MGroupSlot(
      header: MGroupHeader(title),
      body: Column(
        children: items.map((GroupBookingItem item) {
          return MGroupBookingWidget(item);
        }).toList(),
      ),
      footer: Padding(
        padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            DecoratedBox(
              decoration: new BoxDecoration(
                color: Colors.red[100],
                borderRadius: BorderRadius.circular(100.0),
              ),
              child: Padding(
                padding:
                    const EdgeInsets.symmetric(vertical: 2.0, horizontal: 10.0),
                child: MText(
                  "4件拼团>",
                  fontSize: 12.0,
                  color: Colors.red,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

// 团购列表条目
class MGroupBookingWidget extends StatelessWidget {
  final GroupBookingItem item;
  MGroupBookingWidget(this.item);

  @override
  Widget build(BuildContext context) {
    final double height = 80.0;
    final double fontLagSize = 16.0;
    final double fontSmallSize = 12.0;

    final Color fontColor1 = Colors.red;
    final Color fontColor2 = Colors.grey;
    final Color fontColor3 = Colors.white;

    final Color borderColor = Colors.red;

    return Padding(
      padding: const EdgeInsets.only(bottom: 10.0),
      child: Row(
        children: <Widget>[
          Image.network(
            item.imageSrc,
            width: height,
            height: height,
          ),
          Expanded(
            child: Container(
              padding: EdgeInsets.only(left: 10.0),
              height: height,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  MText(item.name),
                  DecoratedBox(
                    decoration: new BoxDecoration(
                      borderRadius: BorderRadius.circular(100.0),
                      border: new Border.all(color: borderColor, width: 1.0),
                    ),
                    child: Padding(
                      padding: const EdgeInsets.only(right: 8.0),
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          DecoratedBox(
                            decoration: new BoxDecoration(
                              color: borderColor,
                              borderRadius: BorderRadius.circular(100.0),
                            ),
                            child: Padding(
                              padding: const EdgeInsets.symmetric(
                                  vertical: 2.0, horizontal: 8.0),
                              child: MText(
                                "${item.groupCounts}人团",
                                fontSize: fontSmallSize,
                                color: fontColor3,
                              ),
                            ),
                          ),
                          MText(
                            ": 拼团省${item.groupFree/100}元",
                            fontSize: fontSmallSize,
                            color: fontColor1,
                            isBold: true,
                          ),
                        ],
                      ),
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          MText("拼团价",
                              fontSize: fontSmallSize, color: fontColor1),
                          MText("￥",
                              fontSize: fontSmallSize,
                              color: fontColor1,
                              isBold: true),
                          MText("${item.groupPrice/100}",
                              fontSize: fontLagSize,
                              color: fontColor1,
                              isBold: true),
                          MText("￥${item.price/100}",
                              fontSize: fontSmallSize, color: fontColor2),
                        ],
                      ),
                      MText("已拼${item.grouped}件",
                          fontSize: fontSmallSize, color: fontColor2),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
